<template>
  <div class="minio-audit-logs">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="page-title">
        <div class="title-with-back">
          <el-button 
            type="primary" 
            :icon="ArrowLeft" 
            @click="goBack"
            class="blue-return-button"
            circle
          />
          <div class="title-content">
            <div class="title-main">
              <el-icon class="title-icon"><FolderOpened /></el-icon>
              <h2>MinIO审计日志统计</h2>
            </div>
            <p class="page-description">
              <el-icon><Document /></el-icon>
              <span>MinIO对象存储审计日志，监控存储访问行为和异常操作</span>
            </p>
          </div>
        </div>
      </div>
    </div>

    <!-- 时间范围选择器 -->
    <el-card class="filter-card">
      <template #header>
        <div class="card-header">
          <span><el-icon><Timer /></el-icon> 时间范围</span>
          <el-button @click="refreshData" :icon="Refresh" size="small" :loading="loading">刷新</el-button>
        </div>
      </template>
      <div class="time-selector">
        <div class="time-quick-buttons">
          <el-button 
            :class="['time-btn', 'time-btn-all', { 'active': selectedTimeRange === 'all' }]"
            @click="selectTimeRange('all')"
            size="default"
          >
            全部
          </el-button>
          <el-button 
            :class="['time-btn', 'time-btn-1h', { 'active': selectedTimeRange === '1h' }]"
            @click="selectTimeRange('1h')"
            size="default"
          >
            1小时
          </el-button>
          <el-button 
            :class="['time-btn', 'time-btn-1d', { 'active': selectedTimeRange === '1d' }]"
            @click="selectTimeRange('1d')"
            size="default"
          >
            1天
          </el-button>
          <el-button 
            :class="['time-btn', 'time-btn-3d', { 'active': selectedTimeRange === '3d' }]"
            @click="selectTimeRange('3d')"
            size="default"
          >
            3天
          </el-button>
          <el-button 
            :class="['time-btn', 'time-btn-7d', { 'active': selectedTimeRange === '7d' }]"
            @click="selectTimeRange('7d')"
            size="default"
          >
            7天
          </el-button>
        </div>
        <div class="custom-time-selector">
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            @change="handleCustomTimeChange"
            style="width: 280px;"
          />
          <el-time-picker
            v-model="startTime"
            placeholder="开始时间"
            format="HH:mm:ss"
            value-format="HH:mm:ss"
            @change="handleCustomTimeChange"
            style="width: 120px;"
          />
          <span style="color: #909399;">至</span>
          <el-time-picker
            v-model="endTime"
            placeholder="结束时间"
            format="HH:mm:ss"
            value-format="HH:mm:ss"
            @change="handleCustomTimeChange"
            style="width: 120px;"
          />
        </div>
      </div>
    </el-card>

    <!-- 概览卡片 -->
    <el-row :gutter="20" class="overview-row" v-loading="loading">
      <el-col :span="4">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon requests">
              <el-icon><DocumentCopy /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ formatNumber(overview.total_requests) }}</div>
              <div class="stat-label">请求总量</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon response-time">
              <el-icon><Timer /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ overview.avg_response_time || 0 }}ms</div>
              <div class="stat-label">平均响应时间</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon success">
              <el-icon><SuccessFilled /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ overview.success_rate || 0 }}%</div>
              <div class="stat-label">成功率</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon errors">
              <el-icon><CircleClose /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ overview.error_count || 0 }}</div>
              <div class="stat-label">错误数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon upload">
              <el-icon><Upload /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ formatBytes(overview.total_upload_bytes) }}</div>
              <div class="stat-label">上传流量</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon download">
              <el-icon><Download /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ formatBytes(overview.total_download_bytes) }}</div>
              <div class="stat-label">下载流量</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 请求趋势图 -->
    <el-card class="trend-chart-card" v-loading="loading">
      <template #header>
        <div class="card-header">
          <span><el-icon><DataLine /></el-icon> 请求趋势（{{ trendGranularityLabel }}）</span>
        </div>
      </template>
      <div ref="trendChartRef" style="width: 100%; height: 300px;"></div>
    </el-card>

    <!-- API分布和桶统计 -->
    <el-row :gutter="20">
      <el-col :span="12">
        <el-card class="api-stats-card" v-loading="loading">
          <template #header>
            <div class="card-header">
              <span><el-icon><PieChart /></el-icon> API类型分布</span>
            </div>
          </template>
          <div ref="apiChartRef" style="width: 100%; height: 350px;"></div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="bucket-stats-card" v-loading="loading">
          <template #header>
            <div class="card-header">
              <span><el-icon><Box /></el-icon> 桶使用统计（Top 10）</span>
            </div>
          </template>
          <el-table :data="bucketStats.slice(0, 10)" style="width: 100%" max-height="350">
            <el-table-column prop="bucket" label="桶名称" min-width="150" show-overflow-tooltip />
            <el-table-column prop="request_count" label="请求数" width="100" align="right">
              <template #default="scope">
                {{ formatNumber(scope.row.request_count) }}
              </template>
            </el-table-column>
            <el-table-column label="上传" width="100" align="right">
              <template #default="scope">
                {{ formatBytes(scope.row.upload_bytes) }}
              </template>
            </el-table-column>
            <el-table-column label="下载" width="100" align="right">
              <template #default="scope">
                {{ formatBytes(scope.row.download_bytes) }}
              </template>
            </el-table-column>
            <el-table-column prop="error_count" label="错误数" width="80" align="right">
              <template #default="scope">
                <span :style="{ color: scope.row.error_count > 0 ? '#f56c6c' : '' }">
                  {{ scope.row.error_count }}
                </span>
              </template>
            </el-table-column>
          </el-table>
          <el-empty v-if="!bucketStats.length" description="暂无数据" />
        </el-card>
      </el-col>
    </el-row>

    <!-- 流量趋势图 -->
    <el-card class="traffic-chart-card" v-loading="loading">
      <template #header>
        <div class="card-header">
          <span><el-icon><TrendCharts /></el-icon> 流量趋势（{{ trendGranularityLabel }} - 上传/下载）</span>
        </div>
      </template>
      <div ref="trafficChartRef" style="width: 100%; height: 300px;"></div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { 
  FolderOpened,
  Refresh, 
  DocumentCopy, 
  Timer, 
  SuccessFilled, 
  CircleClose,
  Upload,
  Download,
  DataLine,
  PieChart,
  Box,
  TrendCharts,
  ArrowLeft,
  Document
} from '@element-plus/icons-vue'
import * as echarts from 'echarts'
import api from '@/utils/api'

const router = useRouter()
const loading = ref(false)
const trendChartRef = ref(null)
const apiChartRef = ref(null)
const trafficChartRef = ref(null)
let trendChart = null
let apiChart = null
let trafficChart = null

// 时间范围
const selectedTimeRange = ref('all') // 当前选中的快捷范围
const dateRange = ref([]) // 自定义日期范围
const startTime = ref('00:00:00') // 开始时间
const endTime = ref('23:59:59') // 结束时间

// 概览数据
const overview = ref({
  total_requests: 0,
  avg_response_time: 0,
  success_rate: 0,
  error_count: 0,
  total_upload_bytes: 0,
  total_download_bytes: 0
})

// API统计数据
const apiStats = ref([])

// 桶统计数据
const bucketStats = ref([])

// 趋势数据
const trendData = ref([])

// 趋势粒度标签
const trendGranularityLabel = ref('按小时')

// 返回上一页
const goBack = () => {
  router.back()
}

// 格式化字节数
const formatBytes = (bytes) => {
  if (!bytes || bytes === 0) return '0 B'
  const k = 1024
  const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
  const i = Math.floor(Math.log(bytes) / Math.log(k))
  return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i]
}

// 格式化数字
const formatNumber = (num) => {
  if (!num) return '0'
  if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M'
  if (num >= 1000) return (num / 1000).toFixed(1) + 'K'
  return num.toString()
}

// 获取概览统计
const fetchOverview = async () => {
  try {
    const response = await api.get('/logs/minio/overview', {
      params: getTimeRangeParams()
    })
    
    if (response.data.success) {
      overview.value = response.data.data
    }
  } catch (error) {
    ElMessage.error('获取概览统计失败: ' + (error.response?.data?.message || error.message))
  }
}

// 获取API统计
const fetchApiStats = async () => {
  try {
    const response = await api.get('/logs/minio/api-stats', {
      params: getTimeRangeParams()
    })
    
    if (response.data.success) {
      apiStats.value = response.data.data.apis || []
      renderApiChart()
    }
  } catch (error) {
    // API统计失败静默处理
  }
}

// 获取桶统计
const fetchBucketStats = async () => {
  try {
    const response = await api.get('/logs/minio/bucket-stats', {
      params: getTimeRangeParams()
    })
    
    if (response.data.success) {
      bucketStats.value = response.data.data.buckets || []
    }
  } catch (error) {
    // 桶统计失败静默处理
  }
}

// 根据时间范围自动选择合适的粒度
const getGranularity = () => {
  switch (selectedTimeRange.value) {
    case 'all':
      // 全部数据，使用天粒度避免数据点过多
      trendGranularityLabel.value = '按天'
      return 'day'
    case '1h':
      // 1小时，使用分钟粒度更细致
      trendGranularityLabel.value = '按分钟'
      return 'minute'
    case '1d':
      // 1天，使用小时粒度
      trendGranularityLabel.value = '按小时'
      return 'hour'
    case '3d':
      // 3天，使用小时粒度（72个点可接受）
      trendGranularityLabel.value = '按小时'
      return 'hour'
    case '7d':
      // 7天，使用天粒度（168小时太多，7天刚好）
      trendGranularityLabel.value = '按天'
      return 'day'
    case 'custom':
      // 自定义时间，根据时间跨度智能选择
      if (dateRange.value && dateRange.value.length === 2) {
        const start = new Date(dateRange.value[0])
        const end = new Date(dateRange.value[1])
        const diffDays = (end - start) / (1000 * 60 * 60 * 24)
        
        if (diffDays <= 1) {
          trendGranularityLabel.value = '按小时'
          return 'hour'
        } else if (diffDays <= 7) {
          trendGranularityLabel.value = '按小时'
          return 'hour'
        } else {
          trendGranularityLabel.value = '按天'
          return 'day'
        }
      }
      trendGranularityLabel.value = '按小时'
      return 'hour'
    default:
      trendGranularityLabel.value = '按小时'
      return 'hour'
  }
}

// 获取趋势
const fetchTrend = async () => {
  try {
    const granularity = getGranularity()
    
    const response = await api.get('/logs/minio/trend', {
      params: {
        ...getTimeRangeParams(),
        granularity: granularity
      }
    })
    
    if (response.data.success) {
      trendData.value = response.data.data.trends || []
      renderTrendChart()
      renderTrafficChart()
    }
  } catch (error) {
    // 趋势数据失败静默处理
  }
}

// 渲染请求趋势图
const renderTrendChart = () => {
  if (!trendChartRef.value || !trendData.value.length) return
  
  if (!trendChart) {
    trendChart = echarts.init(trendChartRef.value)
  }
  
  const times = trendData.value.map(item => item.time)
  const counts = trendData.value.map(item => item.request_count)
  
  const option = {
    tooltip: {
      trigger: 'axis'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '10%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: times,
      axisLabel: {
        rotate: 45,
        formatter: (value) => {
          // 根据粒度显示不同格式
          const granularity = getGranularity()
          if (granularity === 'minute') {
            return value.slice(11, 16) // HH:mm
          } else if (granularity === 'hour') {
            return value.slice(11, 13) + '时' // HH时
          } else {
            return value.slice(5, 10) // MM-DD
          }
        }
      }
    },
    yAxis: {
      type: 'value',
      name: '请求数'
    },
    series: [{
      name: '请求数',
      type: 'line',
      smooth: true,
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          { offset: 0, color: 'rgba(58, 132, 255, 0.5)' },
          { offset: 1, color: 'rgba(58, 132, 255, 0.1)' }
        ])
      },
      data: counts
    }]
  }
  
  trendChart.setOption(option)
}

// 渲染API分布饼图
const renderApiChart = () => {
  if (!apiChartRef.value || !apiStats.value.length) return
  
  if (!apiChart) {
    apiChart = echarts.init(apiChartRef.value)
  }
  
  // 只显示Top 10，其他合并为"其他"
  const topN = 10
  let data = []
  let otherCount = 0
  
  if (apiStats.value.length <= topN) {
    data = apiStats.value.map(item => ({
      name: item.api_name,
      value: item.request_count
    }))
  } else {
    // 取前N个
    data = apiStats.value.slice(0, topN).map(item => ({
      name: item.api_name,
      value: item.request_count
    }))
    // 其他的合并
    otherCount = apiStats.value.slice(topN).reduce((sum, item) => sum + item.request_count, 0)
    if (otherCount > 0) {
      data.push({
        name: '其他',
        value: otherCount
      })
    }
  }
  
  const option = {
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b}: {c} ({d}%)'
    },
    legend: {
      orient: 'vertical',
      right: 10,
      top: 'center',
      textStyle: {
        fontSize: 11
      },
      type: 'scroll',  // 启用滚动
      pageButtonPosition: 'end',
      pageIconSize: 12,
      pageTextStyle: {
        fontSize: 11
      }
    },
    series: [{
      name: 'API调用',
      type: 'pie',
      radius: ['45%', '70%'],
      center: ['35%', '50%'],
      avoidLabelOverlap: false,
      itemStyle: {
        borderRadius: 10,
        borderColor: '#fff',
        borderWidth: 2
      },
      label: {
        show: false
      },
      emphasis: {
        label: {
          show: true,
          fontSize: 14,
          fontWeight: 'bold'
        }
      },
      labelLine: {
        show: false
      },
      data: data
    }]
  }
  
  apiChart.setOption(option)
}

// 渲染流量趋势图
const renderTrafficChart = () => {
  if (!trafficChartRef.value || !trendData.value.length) return
  
  if (!trafficChart) {
    trafficChart = echarts.init(trafficChartRef.value)
  }
  
  const times = trendData.value.map(item => item.time)
  
  // 数据库存储单位是字节(Bytes)，转换为MB显示更直观
  // 因为流量数据通常较大，使用MB单位更合适
  const uploadData = trendData.value.map(item => ((item.total_rx_bytes || 0) / 1024 / 1024).toFixed(2))
  const downloadData = trendData.value.map(item => ((item.total_tx_bytes || 0) / 1024 / 1024).toFixed(2))
  
  const option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          show: false  // 隐藏坐标轴上的数值标签，避免与tooltip数值混淆
        }
      },
      formatter: function(params) {
        let result = params[0].axisValue + '<br/>'
        params.forEach(param => {
          result += `${param.marker} ${param.seriesName}: ${param.value} MB<br/>`
        })
        return result
      }
    },
    legend: {
      data: ['上传流量', '下载流量'],
      bottom: 0
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '15%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: times,
      axisLabel: {
        rotate: 45,
        formatter: (value) => {
          // 根据粒度显示不同格式
          const granularity = getGranularity()
          if (granularity === 'minute') {
            return value.slice(11, 16) // HH:mm
          } else if (granularity === 'hour') {
            return value.slice(11, 13) + '时' // HH时
          } else {
            return value.slice(5, 10) // MM-DD
          }
        }
      }
    },
    yAxis: {
      type: 'value',
      name: '流量 (MB)',
      axisLabel: {
        formatter: (value) => value.toFixed(0)
      }
    },
    series: [
      {
        name: '上传流量',
        type: 'line',
        smooth: true,
        data: uploadData,
        lineStyle: {
          color: '#67c23a'
        },
        itemStyle: {
          color: '#67c23a'
        }
      },
      {
        name: '下载流量',
        type: 'line',
        smooth: true,
        data: downloadData,
        lineStyle: {
          color: '#409eff'
        },
        itemStyle: {
          color: '#409eff'
        }
      }
    ]
  }
  
  trafficChart.setOption(option)
}

// 刷新数据
const refreshData = async () => {
  loading.value = true
  try {
    await Promise.all([
      fetchOverview(),
      fetchApiStats(),
      fetchBucketStats(),
      fetchTrend()
    ])
    ElMessage.success('数据刷新成功')
  } catch (error) {
    ElMessage.error('刷新数据失败')
  } finally {
    loading.value = false
  }
}

// 快捷时间范围选择
const selectTimeRange = (range) => {
  selectedTimeRange.value = range
  dateRange.value = [] // 清空自定义日期
  startTime.value = '00:00:00' // 重置开始时间
  endTime.value = '23:59:59' // 重置结束时间
  
  refreshData()
}

// 自定义时间范围改变
const handleCustomTimeChange = () => {
  if (dateRange.value && dateRange.value.length === 2) {
    selectedTimeRange.value = 'custom' // 标记为自定义
    refreshData()
  }
}

// 格式化日期为本地时间字符串（YYYY-MM-DD HH:mm:ss）
const formatLocalDateTime = (date) => {
  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0')
  const day = String(date.getDate()).padStart(2, '0')
  const hours = String(date.getHours()).padStart(2, '0')
  const minutes = String(date.getMinutes()).padStart(2, '0')
  const seconds = String(date.getSeconds()).padStart(2, '0')
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}

// 获取时间范围参数
const getTimeRangeParams = () => {
  if (selectedTimeRange.value === 'all') {
    return {} // 全部数据，不传时间参数
  }
  
  if (dateRange.value && dateRange.value.length === 2) {
    // 使用自定义日期和时间
    const start = `${dateRange.value[0]} ${startTime.value || '00:00:00'}`
    const end = `${dateRange.value[1]} ${endTime.value || '23:59:59'}`
    return {
      start_time: start,
      end_time: end
    }
  }
  
  // 使用快捷时间（本地时间，东八区）
  const now = new Date()
  const end = formatLocalDateTime(now)
  let start = ''
  
  switch (selectedTimeRange.value) {
    case '1h':
      start = formatLocalDateTime(new Date(now.getTime() - 60 * 60 * 1000))
      break
    case '1d':
      start = formatLocalDateTime(new Date(now.getTime() - 24 * 60 * 60 * 1000))
      break
    case '3d':
      start = formatLocalDateTime(new Date(now.getTime() - 3 * 24 * 60 * 60 * 1000))
      break
    case '7d':
      start = formatLocalDateTime(new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000))
      break
  }
  
  return start ? { start_time: start, end_time: end } : {}
}

// 页面加载时获取数据
onMounted(() => {
  refreshData()
  
  // 监听窗口大小变化
  window.addEventListener('resize', () => {
    if (trendChart) trendChart.resize()
    if (apiChart) apiChart.resize()
    if (trafficChart) trafficChart.resize()
  })
})
</script>

<style scoped>
.minio-audit-logs {
  padding: 0;
}

/* 使用全局设计系统样式 */

/* 页面头部布局 */
.title-with-back {
  display: flex;
  align-items: flex-start;
  gap: 15px;
}

.blue-return-button {
  background: linear-gradient(135deg, #409eff 0%, #66b3ff 100%);
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
  transition: all 0.3s ease;
  flex-shrink: 0;
  margin-top: 2px;
}

.blue-return-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(64, 158, 255, 0.4);
  background: linear-gradient(135deg, #66b3ff 0%, #409eff 100%);
}

.title-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 卡片header样式 */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

.card-header .el-icon {
  font-size: 16px;
  color: #606266;
}

.filter-card {
  margin-bottom: 16px;
}

.time-selector {
  display: flex;
  align-items: center;
  gap: 16px;
}

.time-quick-buttons {
  display: flex;
  gap: 8px;
}

/* 时间按钮基础样式 */
.time-btn {
  border: 2px solid;
  font-weight: 500;
  transition: all 0.3s ease;
}

/* 全部 - 灰色 */
.time-btn-all {
  border-color: #909399;
  color: #606266;
  background-color: #f4f4f5;
}

.time-btn-all:hover {
  border-color: #909399;
  color: #606266;
  background-color: #e9e9eb;
}

.time-btn-all.active {
  border-color: #909399;
  color: #fff;
  background-color: #909399;
}

/* 1小时 - 紫色 */
.time-btn-1h {
  border-color: #9b59b6;
  color: #9b59b6;
  background-color: #f3e8ff;
}

.time-btn-1h:hover {
  border-color: #9b59b6;
  color: #9b59b6;
  background-color: #e6d5f5;
}

.time-btn-1h.active {
  border-color: #9b59b6;
  color: #fff;
  background-color: #9b59b6;
}

/* 1天 - 蓝色 */
.time-btn-1d {
  border-color: #409eff;
  color: #409eff;
  background-color: #ecf5ff;
}

.time-btn-1d:hover {
  border-color: #409eff;
  color: #409eff;
  background-color: #d9ecff;
}

.time-btn-1d.active {
  border-color: #409eff;
  color: #fff;
  background-color: #409eff;
}

/* 3天 - 橙色 */
.time-btn-3d {
  border-color: #e6a23c;
  color: #e6a23c;
  background-color: #fdf6ec;
}

.time-btn-3d:hover {
  border-color: #e6a23c;
  color: #e6a23c;
  background-color: #faecd8;
}

.time-btn-3d.active {
  border-color: #e6a23c;
  color: #fff;
  background-color: #e6a23c;
}

/* 7天 - 绿色 */
.time-btn-7d {
  border-color: #67c23a;
  color: #67c23a;
  background-color: #f0f9ff;
}

.time-btn-7d:hover {
  border-color: #67c23a;
  color: #67c23a;
  background-color: #e1f3d8;
}

.time-btn-7d.active {
  border-color: #67c23a;
  color: #fff;
  background-color: #67c23a;
}

.custom-time-selector {
  display: flex;
  align-items: center;
  gap: 12px;
}

.overview-row {
  margin-bottom: 16px;
}

.stat-card {
  height: 140px;
}

.stat-card :deep(.el-card__body) {
  padding: 14px;
  height: 100%;
}

.stat-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  height: 100%;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: white;
  flex-shrink: 0;
}

.stat-icon.requests {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-icon.response-time {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-icon.success {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.stat-icon.errors {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.stat-icon.upload {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.stat-icon.download {
  background: linear-gradient(135deg, #fa71cd 0%, #c471f5 100%);
}

.stat-info {
  text-align: center;
  width: 100%;
  min-width: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-value {
  font-size: 22px;
  font-weight: bold;
  color: #303133;
  line-height: 1.1;
}

.stat-label {
  font-size: 12px;
  color: #909399;
  white-space: nowrap;
  text-align: center;
  width: 100%;
  line-height: 1.3;
}

.trend-chart-card,
.api-stats-card,
.bucket-stats-card,
.traffic-chart-card {
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
</style>

